package com.ruoyi.extdata.domain;

import lombok.Getter;
import lombok.Setter;

import javax.xml.bind.annotation.*;

@Setter
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "soap:Envelope")
public class XdsEntity {

    @XmlAttribute(name = "xmlns:xsi")
    protected String xsi = "http://www.w3.org/2001/XMLSchema-instance";

    @XmlAttribute(name = "xmlns:xsd")
    protected String xsd = "http://www.w3.org/2001/XMLSchema";

    @XmlAttribute(name = "xmlns:soap")
    protected String soap = "http://schemas.xmlsoap.org/soap/envelope/";

    @XmlElement(name = "soap:Body")
    private SoapBody soapBody;

    public XdsEntity replaceTicket(String ticket){
        this.getSoapBody().getConsumerMatch().setDataTicket(ticket);
        return this;
    }

    public XdsEntity isTicketValid(String ticket){
        SoapBody soapBody = new SoapBody();
        IsTicketValid isTicketValid = new IsTicketValid();
        isTicketValid.setFirstCentralNigeriaWebServiceTicket(ticket);
        soapBody.setIsTicketValid(isTicketValid);
        this.setSoapBody(soapBody);
        return this;
    }

    public XdsEntity login(String userName, String password){
        SoapBody soapBody = new SoapBody();
        XdsLogin login = new XdsLogin();
        login.setUserName(userName);
        login.setPassword(password);
        soapBody.setLogin(login);
        this.setSoapBody(soapBody);
        return this;
    }

    public XdsEntity consumerMatch(ConsumerMatch consumerMatch){
        SoapBody soapBody = new SoapBody();
        soapBody.setConsumerMatch(consumerMatch);
        this.setSoapBody(soapBody);
        return this;
    }

    public XdsEntity consumerFullCreditReport(ConsumerFullCreditReport consumerFullCreditReport){
        SoapBody soapBody = new SoapBody();
        soapBody.setConsumerFullCreditReport(consumerFullCreditReport);
        this.setSoapBody(soapBody);
        return this;
    }

    @Override
    public String toString() {
        return "XdsEntity{" +
                "xsi='" + xsi + '\'' +
                ", xsd='" + xsd + '\'' +
                ", soap='" + soap + '\'' +
                ", soapBody=" + soapBody +
                '}';
    }
}


@Setter
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "soap:Body")
class SoapBody {

    @XmlElement(name = "IsTicketValid")
    private IsTicketValid isTicketValid;

    @XmlElement(name = "Login")
    private XdsLogin login;

    @XmlElement(name = "ConnectConsumerMatch")
    private ConsumerMatch consumerMatch;

    @XmlElement(name = "GetConsumerFullCreditReport")
    private ConsumerFullCreditReport consumerFullCreditReport;

    @Override
    public String toString() {
        return "SoapBody{" +
                "isTicketValid=" + isTicketValid +
                ", login=" + login +
                ", consumerMatch=" + consumerMatch +
                ", consumerFullCreditReport=" + consumerFullCreditReport +
                '}';
    }
}

@Setter
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Login")
class XdsLogin {

    @XmlAttribute(name = "xmlns")
    protected String xmlns = "https://als.firstcentralcreditbureau.com/FirstCentralNigeriaWebService";

    @XmlElement(name = "UserName")
    private String userName;

    @XmlElement(name = "Password")
    private String password;

    @Override
    public String toString() {
        return "XdsLogin{" +
                "xmlns='" + xmlns + '\'' +
                ", userName='" + userName + '\'' +
                ", password='" + password + '\'' +
                '}';
    }
}

@Setter
@Getter
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "IsTicketValid")
class IsTicketValid {

    @XmlAttribute(name = "xmlns")
    protected String xmlns = "https://als.firstcentralcreditbureau.com/FirstCentralNigeriaWebService";

    @XmlElement(name = "FirstCentralNigeriaWebServiceTicket")
    private String firstCentralNigeriaWebServiceTicket;

    @Override
    public String toString() {
        return "IsTicketValid{" +
                "xmlns='" + xmlns + '\'' +
                ", firstCentralNigeriaWebServiceTicket='" + firstCentralNigeriaWebServiceTicket + '\'' +
                '}';
    }
}

